package cn.wolfcode.luowowo;

import cn.wolfcode.luowowo.website.interceptor.CheckLoginInterrceptor;
import cn.wolfcode.luowowo.website.resolver.UserInfoArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@SpringBootApplication
public class Website implements WebMvcConfigurer{
    @Autowired
    private CheckLoginInterrceptor checkLoginInterrceptor;
    @Autowired
    private UserInfoArgumentResolver userInfoArgumentResolver;

    public static void main(String[] args) {
        SpringApplication.run(Website.class, args);
    }
    //注册拦截器
    public  void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(checkLoginInterrceptor)
                .excludePathPatterns("/images/**","/js/**","/login.html","/styles/**","/regist.html")
                .addPathPatterns("/**");
    }
    //注册参数解析器
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers){
        resolvers.add(userInfoArgumentResolver);
    }
}
